<template>
  <div class="qs-preview">
    <el-dialog title="题目预览" @open="handleOpen" :visible="dialogVisible" @close="closeDialog">
      <el-row>
        <el-col :span="6">【题型】: {{questionsDetail.questionType | tx}}</el-col>
        <el-col :span="6">【编号】: {{questionsDetail.id}}</el-col>
        <el-col :span="6">【难度】: {{questionsDetail.difficulty | nd}}</el-col>
        <el-col :span="6">【标签】: {{questionsDetail.tags}}</el-col>
        <el-col :span="6">【学科】: {{questionsDetail.subjectName}}</el-col>
        <el-col :span="6">【目录】: {{questionsDetail.directoryName}}</el-col>
        <el-col :span="6">【方向】: {{questionsDetail.direction}}</el-col>
      </el-row>
      <hr />
      【题干】:<div v-html="questionsDetail.question" style="color: blue"></div>
      <div v-if="questionsDetail.questionType !== '3'" style="padding-bottom: 5px">
        <div>{{questionsDetail.questionType | tx}} 选项: (以下选中的选项为正确答案)</div>
        <div v-for="item in questionsDetail.options" :key="item.id" style="padding: 5px 0">
          <el-radio v-if="questionsDetail.questionType === '1'" :value="item.isRight" :label="1">{{item.title}}</el-radio>
          <el-checkbox v-if="questionsDetail.questionType === '2'" :value="item.isRight ? true : false">{{item.title}}</el-checkbox>
        </div>
      </div>
      <hr />
      【参考答案】: <el-button type="danger" size="small" @click="previewVideo()">视频答案预览</el-button>
      <div class="video" v-show="play">
        <video ref="video" :src="questionsDetail.videoURL" controls></video>
      </div>
      <hr />
      【答案解析】: <div style="display: inline-block" v-html="questionsDetail.answer"></div>
      <hr />
      【题目备注】: {{ questionsDetail.remarks }}
      <div></div>
       <div slot="footer" class="footer">
        <el-button type="primary" @click="closeDialog">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { detail } from '@/api/hmmm/questions.js'
import { difficulty, questionType } from '@/api/hmmm/constants.js'

export default {
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    questionsInfo: {
      type: Object,
      default: () => {}
    }
  },
  filters: {
    tx (val) {
      if (val) return questionType.find(item => item.value === +val).label + '题'
    },
    nd (val) {
      if (val) return difficulty.find(item => item.value === +val).label
    }
  },
  data () {
    return {
      questionsDetail: {},
      play: false
    }
  },

  methods: {
    closeDialog () {
      this.$emit('update:dialogVisible', false)
      this.play = false
      this.$refs.video.pause()
    },

    async handleOpen () {
      this.dialogVisible = true
      const { data } = await detail({ id: this.questionsInfo.id })
      this.questionsDetail = data
    },
    previewVideo () {
      this.play = true
      this.$refs.video.play()
    }
  }
}
</script>

<style scoped lang="scss">
.qs-preview {
  .el-col {
    padding: 10px 0;
  }
  .footer{
    text-align: right;
  }
}
.video{
  width: 400px;
  height: 300px;
  video {
    width: 100%;
    height: 100%;
  }
}
</style>
